package controller

import (
	"context"
	"tk-gen/model"
	"tk-gen/types"
)

// Schema returns the c for the given database
func Schema(dsn string) ([]types.Schema, error) {
	args := types.Args{
		Verbose: false,
	}
	data, err := model.Load(context.Background(), "schema", dsn, &args)
	if err != nil {
		return nil, err
	}
	return data.Schemas, nil
}

// Query returns the results for the given query
func Query(dsn string, query string, rows bool) ([]types.Query, error) {
	args := types.Args{
		Verbose: false,
		QueryParams: types.QueryParams{
			Query:     query,
			Delimiter: "%%",
			Rows:      rows,
		},
	}
	data, err := model.Load(context.Background(), "query", dsn, &args)
	if err != nil {
		return nil, err
	}
	return data.Queries, nil
}
